package com.yun.algorithmproblem.leetcode;

import java.util.HashMap;

public class Leetcode2506 {

    public static void main(String[] args) {
        Leetcode2506 obj = new Leetcode2506();
        String[] words = new String[]{"aba", "aabb", "abcd", "bac", "aabc"};
        obj.similarPairs(words);
    }

    public int similarPairs(String[] words) {
        int ans = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (String word : words) {
            int index = 0;
            for (int i = 0; i < word.length(); i++) {
                char c = word.charAt(i);
                index = index | (1 << (c - 'a' + 1));
            }
            Integer merge = map.merge(index, 1, Integer::sum);
            ans += merge - 1;
        }
        return ans;
    }
}
